#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>

//#include <ncurses.h>
//#include <menu.h>



#include "read_fan_temperature.h"
#include "../ec_it8733_inc/ec_it8733_dev.h"

#include "ec_it8733_rw.h"

//#define DBG_UART_PRT
//#include "dbg_prt.h"
#include "../ec_it8733_inc/dbg_prt.h"


#if 0
int const_nMaxColumn()
{
	return (const_nMaxCell*3-2);
}
#endif



EN_RUN_STATE_TYPE en_run_state=RUN_STATE_STOP;
EN_KEY_VALUE_TYPE en_key_value= KEY_VALUE_OTHERS;
void *thr_fn(void *arg);

void *thr_fn(void *arg)
{
    //printids("new thread: ");
	int ncountsleep=0;
	unsigned char u8FanPwmLocal;

	
	usleep(100);
	while(en_run_state==RUN_STATE_START)
	{
		if(ncountsleep%20 == 0 /*|| u8FanPwmLocal!=getFanPwmBox()*/)
		{
			//u8FanPwmLocal=getFanPwmBox();
			if(en_run_state==RUN_STATE_START)
			{
				int nCpuTemp; int nMainBoardTemp; int nChassisTemp;
				int nCpuFan;
				CEcIt8733Rw::getInstance()->ec_it8733_read_cpu_temp( &u8FanPwmLocal, 
					&nCpuTemp, &nMainBoardTemp, &nChassisTemp, &nCpuFan );
#if 0
				dbg_prt("     CPU   temprature = %08d; ",nCpuTemp );
				dbg_prt("main board temprature = %08d; ",nMainBoardTemp );
				dbg_prt("   chassis temprature = %08d; ",nChassisTemp );
				dbg_prt("CPU fan rotation rate = %08d; ",nCpuFan );
#endif

				void disp_cpu_temperature(int nval);
				void disp_main_board_temperature(int nval);
				void disp_chassis_temperature(int nval);
				void disp_cpu_fan(int nval);
				void disp_sleep_msg(char* str);

				disp_cpu_temperature(nCpuTemp);
				disp_main_board_temperature(nMainBoardTemp);
				disp_chassis_temperature(nChassisTemp);
				disp_cpu_fan(nCpuFan);

				dbg_prt("ncountsleep = %08d; ",ncountsleep );
				char str[30];
				sprintf(str, "ncountsleep = %8d; ",ncountsleep/10 );

				disp_sleep_msg(str);

				//mvprintw(defnLineCpuTemp, defnColCpuTemp,             "     CPU   temprature = %08d; ",ncountsleep );
				//mvprintw(defnLineMainBoardTemp, defnColMainBoardTemp, "main board temprature = %08d; ",ncountsleep );
				//mvprintw(defnLineCpuFan, defnColCpuFan,               "CPU fan rotation rate = %08d; ",ncountsleep );
			}
		}
		else
		{
			//dbg_prt("en_run_state: %4d; ncountsleep=%d ", en_run_state, ncountsleep );
		}
		
		usleep(100*1000);
		ncountsleep++;
		
	}
    return NULL;
}
 



